home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_HDF.idb / usr / freeware / include / hdf / linklist.h.z / linklist.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  7.2 KB  |  211 lines

  1. /****************************************************************************
  2.  * NCSA HDF                                                                 *
  3.  * Software Development Group                                               *
  4.  * National Center for Supercomputing Applications                          *
  5.  * University of Illinois at Urbana-Champaign                               *
  6.  * 605 E. Springfield, Champaign IL 61820                                   *
  7.  *                                                                          *
  8.  * For conditions of distribution and use, see the accompanying             *
  9.  * hdf/COPYING file.                                                        *
  10.  *                                                                          *
  11.  ****************************************************************************/
  12.  
  13. /* $Id: linklist.h,v 1.2 1996/05/16 18:42:05 koziol Exp $ */
  14.  
  15. /*-----------------------------------------------------------------------------
  16.  * File:    linklist.h
  17.  * Purpose: header file for linked list API
  18.  * Dependencies: 
  19.  * Invokes:
  20.  * Contents:
  21.  * Structure definitions: 
  22.  * Constant definitions: 
  23.  *---------------------------------------------------------------------------*/
  24.  
  25. /* avoid re-inclusion */
  26. #ifndef __LINKLIST_H
  27. #define __LINKLIST_H
  28.  
  29. #include "hdf.h"
  30.  
  31. /* Definitions for linked-list creation flags */
  32. #define HUL_UNSORTED_LIST   0x0000
  33. #define HUL_SORTED_LIST     0x0001
  34.  
  35. /* Type of the function to compare objects & keys */
  36. typedef intn (*HULsearch_func_t)(const VOIDP obj, const VOIDP key);
  37.  
  38. /* Type of the function to compare two objects */
  39. typedef intn (*HULfind_func_t)(const VOIDP obj1, const VOIDP obj2);
  40.  
  41. /* Linked list information structure used */
  42. typedef struct node_info_struct_tag {
  43.     VOIDP *obj_ptr;         /* pointer associated with the linked list node */
  44.     struct node_info_struct_tag *next;   /* link to list node */
  45.   }node_info_t;
  46.  
  47. /* Linked list head structure */
  48. typedef struct list_head_struct_tag {
  49.     uintn count;            /* # of nodes in the list */
  50.     uintn flags;            /* list creation flags */
  51.     HULfind_func_t cmp_func;    /* node comparison function */
  52.     node_info_t *node_list; /* pointer to a linked list of nodes */
  53.     node_info_t *curr_node; /* pointer to the current node when iterating */
  54.   }list_head_t;
  55.  
  56. #if defined LIST_MASTER | defined LIST_TESTER
  57.  
  58. /* Define this in only one place */
  59. #ifdef LIST_MASTER
  60. /* Pointer to the list node free list */
  61. static node_info_t *node_free_list=NULL;
  62.  
  63. #endif /* LIST_MASTER */
  64.  
  65. /* Useful routines for generally private use */
  66.  
  67. #endif /* LIST_MASTER | LIST_TESTER */
  68.  
  69. #if defined c_plusplus || defined __cplusplus
  70. extern      "C"
  71. {
  72. #endif                          /* c_plusplus || __cplusplus */
  73.  
  74. /******************************************************************************
  75.  NAME
  76.      HULcreate_list - Create a linked list
  77.  
  78.  DESCRIPTION
  79.     Creates a linked list.  The list may either be sorted or un-sorted, based
  80.     on the comparison function.
  81.  
  82.  RETURNS
  83.     Returns a pointer to the list if successful and NULL otherwise
  84.  
  85. *******************************************************************************/
  86. list_head_t *HULcreate_list(HULfind_func_t find_func    /* IN: object comparison function */
  87. );
  88.  
  89. /******************************************************************************
  90.  NAME
  91.      HULdestroy_list - Destroys a linked list
  92.  
  93.  DESCRIPTION
  94.     Destroys a linked list created by HULcreate_list().  This function
  95.     walks through the list and frees all the nodes, then frees the list head.
  96.     Note: this function does not (currently) free the objects in the nodes,
  97.     it just leaves 'em hanging.
  98.  
  99.  RETURNS
  100.     Returns SUCCEED/FAIL.
  101.  
  102. *******************************************************************************/
  103. intn HULdestroy_list(list_head_t *lst    /* IN: list to destroy */
  104. );
  105.  
  106. /******************************************************************************
  107.  NAME
  108.      HULadd_node - Adds an object to a linked-list
  109.  
  110.  DESCRIPTION
  111.     Adds an object to the linked list.  If the list is sorted, the comparison
  112.     function is used to determine where to insert the node, otherwise it is
  113.     inserted at the head of the list.
  114.  
  115.  RETURNS
  116.     Returns SUCCEED/FAIL.
  117.  
  118. *******************************************************************************/
  119. intn HULadd_node(list_head_t *lst,  /* IN: list to modify */
  120.     VOIDP obj                       /* IN: object to add to the list */
  121. );
  122.  
  123. /******************************************************************************
  124.  NAME
  125.      HULsearch_node - Search for an object in a linked-list
  126.  
  127.  DESCRIPTION
  128.     Locate an object in a linked list using a key and comparison function.
  129.  
  130.  RETURNS
  131.     Returns a pointer to the object found in the list, or NULL on failure.
  132.  
  133. *******************************************************************************/
  134. VOIDP HULsearch_node(list_head_t *lst,  /* IN: list to search */
  135.     HULsearch_func_t srch_func,       /* IN: function to use to find node */
  136.     VOIDP key                       /* IN: key of object to search for */
  137. );
  138.  
  139. /******************************************************************************
  140.  NAME
  141.      HULfirst_node - Get the first object in a linked-list
  142.  
  143.  DESCRIPTION
  144.     Returns the first object in a linked-list and prepares the list for
  145.     interating through.
  146.  
  147.  RETURNS
  148.     Returns a pointer to the first object found in the list, or NULL on failure.
  149.  
  150. *******************************************************************************/
  151. VOIDP HULfirst_node(list_head_t *lst   /* IN: list to search */
  152. );
  153.  
  154. /******************************************************************************
  155.  NAME
  156.      HULnext_node - Get the next object in a linked-list
  157.  
  158.  DESCRIPTION
  159.     Returns the next object in a linked-list by walking through the list
  160.  
  161.  RETURNS
  162.     Returns a pointer to the next object found in the list, or NULL on failure.
  163.  
  164. *******************************************************************************/
  165. VOIDP HULnext_node(list_head_t *lst   /* IN: list to search */
  166. );
  167.  
  168. /******************************************************************************
  169.  NAME
  170.      HULremove_node - Removes an object from a linked-list
  171.  
  172.  DESCRIPTION
  173.     Remove an object from a linked list.  The key and comparison function are
  174.     provided locate the object to delete.
  175.  
  176.  RETURNS
  177.     Returns a pointer to the object deleted from the list, or NULL on failure.
  178.  
  179. *******************************************************************************/
  180. VOIDP HULremove_node(list_head_t *lst,  /* IN: list to modify */
  181.     HULsearch_func_t srch_func,       /* IN: function to use to find node to remove */
  182.     VOIDP key                       /* IN: object to add to the list */
  183. );
  184.  
  185. /*--------------------------------------------------------------------------
  186.  NAME
  187.     HULshutdown
  188.  PURPOSE
  189.     Terminate various global items.
  190.  USAGE
  191.     intn HULshutdown()
  192.  RETURNS
  193.     Returns SUCCEED/FAIL
  194.  DESCRIPTION
  195.     Free various buffers allocated in the HUL routines.
  196.  GLOBAL VARIABLES
  197.  COMMENTS, BUGS, ASSUMPTIONS
  198.     Should only ever be called by the "atexit" function HDFend
  199.  EXAMPLES
  200.  REVISION LOG
  201. --------------------------------------------------------------------------*/
  202. intn 
  203. HULshutdown(void);
  204.  
  205. #if defined c_plusplus || defined __cplusplus
  206. }
  207. #endif                          /* c_plusplus || __cplusplus */
  208.  
  209. #endif /* __LINKLIST_H */
  210.  
  211.